#include <iostream>

using namespace std;

float z(float u)
{
	float y1=0.f, y2=0.f, y3=0.f;
	if (u<=4.f)
		y2 = 1.f;
	if (u<=3.5f)
		y3 = 1.f;
	if (u<=10.f/3.f)
		y1 = 1.f;

	return (10.f-3.f*u)*y1 + (4.f-u)*y2 + (14.f-4.f*u)*y3 + 4.f*u;
}

float subgrad(float u)
{
	float y1=0.f, y2=0.f, y3=0.f;
	if (u<=4.f)
		y2 = 1.f;
	if (u<=3.5f)
		y3 = 1.f;
	if (u<=10.f/3.f)
		y1 = 1.f;

	return (4-3*y1-y2-4*y3);
}


void main(void)
{
	float u=0;
	float mu=1;
	float rho=0.5f;

	for(unsigned i=0; i<20; i++)
	{
		cout << "Iteration " << (i+1) << endl;
		float s = subgrad(u);
		cout << "Subgradient: " << s << endl;
		cout << "mu: " << mu << endl;
		u = u - mu*s;
		cout << "u = " << u << endl;
		mu *= rho;
	}
	system("pause");
}